home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-09 | 4.4 KB | 130 lines | [TEXT/R*ch] |
- #include "UTestPrefsDialogHandler.h"
-
- #include <LArray.h>
- #include <LArrayIterator.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
-
- // This one tells the dialog which pane we need to come back in on.
- Int16 StTestPrefsDialogHandler::sLastPanelIndex = 1;
- LArray StTestPrefsDialogHandler::sPanelDataHandles(sizeof(Handle));
-
- //---------------------------------------------------------------------------
- // StTestPrefsDialogHandler::StTestPrefsDialogHandler
- //---------------------------------------------------------------------------
- // Constructor
- StTestPrefsDialogHandler::StTestPrefsDialogHandler(ResIDT inDialogResID, LCommander *inSuper,
- Int16 inLastPaneIndex, ResIDT inMPDResID)
- : StMPDialogHandler(inDialogResID, inSuper, inLastPaneIndex, inMPDResID)
- {
- if ( sPanelDataHandles.GetCount() != (**(MPDHandle)mMPDData).numItems )
- {
- Handle panelData = nil;
- sPanelDataHandles.InsertItemsAt((**(MPDHandle)mMPDData).numItems, LArray::index_First, &panelData);
- }
- }
-
- //---------------------------------------------------------------------------
- // StTestPrefsDialogHandler::~StTestPrefsDialogHandler
- //---------------------------------------------------------------------------
- // Destructor
- StTestPrefsDialogHandler::~StTestPrefsDialogHandler()
- {
- }
-
- //---------------------------------------------------------------------------
- // StTestPrefsDialogHandler::HandleOK
- //---------------------------------------------------------------------------
- void StTestPrefsDialogHandler::HandleOK(void)
- {
- StMPDialogHandler::HandleOK();
-
- // we want to remember the last panel visited so we can get to it next time
- // as the initial panel. This is per HIG.
- sLastPanelIndex = GetCurrentPanelIndex();
-
- // This just fakes out the app into believing the preferences were really changed.
- // of course for a real app you'd probably set them in a preferences file.
- for ( short i = 1; i <= (**(MPDHandle)mMPDData).numItems; i++ )
- {
- Handle newPanelData = RetrievePanelData(i);
- if ( newPanelData != nil )
- {
- Handle temp;
- sPanelDataHandles.FetchItemAt(i, &temp);
- if ( temp != nil )
- ::DisposeHandle(temp);
-
- OSErr anErr = ::HandToHand(&newPanelData);
- ThrowIfOSErr_(anErr);
-
- sPanelDataHandles.AssignItemsAt(1, i, &newPanelData);
- }
- }
- }
-
- //---------------------------------------------------------------------------
- // StTestPrefsDialogHandler::GetPanelData
- //---------------------------------------------------------------------------
- // This particular implementation uses handles it stores in the object itself.
- // We have an array of handles which correspond 1 to 1 to the panes in the
- // dialog. This way it's quite easy to grab the one we want. But this
- // method you have to overide allows you to do it anyway you wish.
- Handle StTestPrefsDialogHandler::GetInitialPanelData(Int16 inPanelIndex)
- {
- Handle temp;
- sPanelDataHandles.FetchItemAt(inPanelIndex, &temp);
- if ( temp == nil )
- {
- temp = GetResource('PREF', 1000 + inPanelIndex - 1);
- ThrowIfResFail_(temp);
- ::DetachResource(temp);
- ThrowIfResError_();
- }
- else
- {
- OSErr anErr = ::HandToHand(&temp);
- ThrowIfOSErr_(anErr);
- }
- return temp;
- }
-
- //---------------------------------------------------------------------------
- // StTestPrefsDialogHandler::GetPanelDefaultData
- //---------------------------------------------------------------------------
- // This particular implementation uses handles it stores in the object itself.
- // We have an array of handles which correspond 1 to 1 to the panes in the
- // dialog. This way it's quite easy to grab the one we want. But this
- // method you have to overide allows you to do it anyway you wish.
- Handle StTestPrefsDialogHandler::GetPanelDefaultData(Int16 inPanelIndex)
- {
- Handle temp = GetResource('DFLT', 1000 + inPanelIndex - 1);
- ThrowIfResFail_(temp);
- ::DetachResource(temp);
- ThrowIfResError_();
- return temp;
- }
-
- //---------------------------------------------------------------------------
- // GetPreferences
- //---------------------------------------------------------------------------
- // Present a Multi-pane dialog for setting the test application's preferences
- //
- void StTestPrefsDialogHandler::GetPreferences(LCommander *inSuper, CommandT inCommand)
- {
- StTestPrefsDialogHandler theHandler(inCommand, inSuper, sLastPanelIndex, inCommand);
-
- // Finish the setup of the dialog panels.
- theHandler.FinishCreate();
-
- theHandler.GetDialog()->Show();
-
- MessageT hitMessage = -1;
- while ( hitMessage != msg_Cancel && hitMessage != msg_OK )
- {
- hitMessage = theHandler.DoDialog();
- }
- }
-
-
-